/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:${USER}
 * Date:${YEAR}-${MONTH}-${DAY}
 * ${TIME}
 */
public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
    }
}

class Solution {
    public int minOperations(int[] nums, int x) {
        int target=0;
        for(int a:nums)target+=a;
        if(x>target){
            return -1;
        }
        target-=x;
        int n=nums.length,ret=-1;
        int sum=0;
        for(int left=0,right=0;right<n;right++){
            sum+=nums[right];
            while(sum>target)sum-=nums[left++];
            if(sum==target)ret=Math.max(ret,right-left+1);
        }
        if(ret==-1){
            return -1;
        }else{
            return n-ret;
        }
    }
}